﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSRoboticsFramework.ActuatorLayer.CompoundActuators;

namespace WheeledTank.LogicLayer
{
    public class WheeledTankModel
    {
        ISteeringVehicle VehicleSubsystem;
        ITankTurret TurretSubsystem;

        public WheeledTankModel(ISteeringVehicle VehicleSubsystem, ITankTurret TurretSubsystem)
        {
            this.VehicleSubsystem = VehicleSubsystem;
            this.TurretSubsystem = TurretSubsystem;
        }

        /// <summary>
        /// Sets/Gets the tank speed and performs the appropriate action depending upon
        /// the value.
        /// </summary>
        public float Speed
        {
            get
            {
                return VehicleSubsystem.Speed;
            }
            set
            {
                VehicleSubsystem.Speed = Math.Abs(value);

                if (value == 0)
                    VehicleSubsystem.Coast();
                else if (value > 0)
                    VehicleSubsystem.Forward();
                else if (value < 0)
                    VehicleSubsystem.Backward();
            }
        }

        /// <summary>
        /// Sets/Gets the tank's steering angle.
        /// </summary>
        public float SteeringAngle
        {
            get
            {
                return VehicleSubsystem.SteeringAngle;
            }
            set
            {
                VehicleSubsystem.SteeringAngle = value;
            }
        }

        public void TurnTurretLeft()
        {
            TurretSubsystem.TurnLeft();
        }

        public void TurnTurretRight()
        {
            TurretSubsystem.TurnRight();
        }

        public void StopHorizontalTurningOfTurret()
        {
            TurretSubsystem.StopHorizontalTurningAndBrake();
        }

        public void TurnTurretUp()
        {
            TurretSubsystem.TurnUp();
        }

        public void TurnTurretDown()
        {
            TurretSubsystem.TurnDown();
        }

        public void StopVerticalTurningOfTurret()
        {
            TurretSubsystem.StopVerticalTurningAndBrake();
        }

        public void FireAndReload()
        {
            TurretSubsystem.FireAndReload();
        }
    }
}
